package com.microinvest.controller.transact;
import com.microinvest.service.BusinessService;
import com.microinvest.util.Result;
import com.microinvest.util.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/transact")
public class TransactController {

    private final BusinessService businessService;

    @Autowired
    public TransactController(BusinessService businessService){
        this.businessService=businessService;
    }

//    @PostMapping("/testToGetUserStockSummary")
//    public Result<String>test(Integer userId){
//        Result result=businessService.testToGetUserStockSummary(userId);
//        return result;
//
//    }

    //用户购买股票(挂单）
    @PostMapping("/userBuyStock")
    public Result<String>userBuyStock(String stockSymbol, double buyPrice,int quantity){
        Map<String,Integer> map = ThreadLocalUtil.get();
        int userId=map.get("userId");
        Result result=businessService.userBuyStock(userId,stockSymbol,buyPrice,quantity);
        return result;
    }

    //用户卖出股票（挂单）
    @PostMapping("/userSellStock")
    public Result<String>userSellStock(String stockSymbol,double sellPrice,int quantity){
        Map<String,Integer> map =ThreadLocalUtil.get();
        int userId=map.get("userId");
        Result result=businessService.userSellStock(userId,stockSymbol,sellPrice,quantity);
        return result;
    }



}
